YAHOO.dasRegistry.setContainers = function(parentCointainer, containerNames){
	var defaultContainers = containerNames;
	var displayContainer = "block";
	var eClientContainer = document.getElementById(parentCointainer);
	for (var key in defaultContainers) {
		containerName = defaultContainers[key];
		containerId = key;

		var html = "<div id='" + containerId + "Container' style='display:" + displayContainer + ";'>";
		html += "<div id='" + containerId + "Style'>";
		html += "<div id='" + containerId + "Display' style='display: inline;'>";
		html += "<span id='" + containerId + "Img'>";
		html += "<img src='img/minus02.gif' class='panelImg'>"
		html += "</span style='display: inline;'>";
		html += containerName;
		html += "</div>";
		html += "</div>";
		html += "<div id='" + containerId + "'></div>";
		html += "</div>";
		eClientContainer.innerHTML += html;
	}
}


YAHOO.dasRegistry.setSpeciesDataTable = function(referenceSpecies){
            var myColumnDefs = [
				{key:"radio", formatter:YAHOO.widget.DataTable.formatRadio},
				{key:"sourceSpecie", sortable:true},
				{key:"sourceRelease", sortable:true},
				{key:"sourceUrl", sortable:true}
            ];
			//console.log(dasRegistryResults.sources);
			var myDataSource = new YAHOO.util.DataSource(referenceSpecies);
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
            myDataSource.responseSchema = 

			{
                fields: [
					{key:"sourceRelease"},
                    {key:"sourceSpecie"},
                    {key:"description"},
					{key:"sourceUrl"},
					{key:"sourceType"},
					{key:"sourceId"},

                ]
            };

			YAHOO.dasRegistry.myDsnDataTable = new YAHOO.widget.DataTable("KDspecies", myColumnDefs, myDataSource);
			
			var myDsnDataTable = YAHOO.dasRegistry.myDsnDataTable;

            var lastSelectedRadioRecord = null;
            myDsnDataTable.subscribe("radioClickEvent", function(oArgs){
                if(lastSelectedRadioRecord) {
                    lastSelectedRadioRecord.setData("radio",false);
                }
                var elRadio = oArgs.target;
                var oRecord = this.getRecord(elRadio);
                oRecord.setData("radio",true);
                lastSelectedRadioRecord = oRecord;
                var name = oRecord.getData("radio");
				sessvars.karyoDas.conf.selectedDsnId = oRecord.getData("sourceId");
				sessvars.karyoDas.conf.specie = oRecord.getData("sourceSpecie");
				YAHOO.dasBrowser.yuiContainer.panel["KDspecies"].hide();
				YAHOO.dasRegistry.makeRegistryRequest();
            });

            return {
                oDS: myDataSource,
                oDT: myDsnDataTable
            };
 }
 
 
 
 
 
YAHOO.dasRegistry.setSourcesDataTable = function(dasSources, requestName){
            var myCustomFormatter = function(elCell, oRecord, oColumn, oData) {
                if(oRecord.getData("field3") > 100) {
                    YAHOO.util.Dom.replaceClass(elCell.parentNode, "down", "up");
                    elCell.innerHTML = '&nbsp;<img src="build/datatable/assets/skins/sam/dt-arrow-up.png">';
                }
                else {
                    YAHOO.util.Dom.replaceClass(elCell.parentNode, "up","down");
                    elCell.innerHTML = '&nbsp;<img src="build/datatable/assets/skins/sam/dt-arrow-dn.png">';
                }
            };      
			
            // Add the custom formatter to the shortcuts
            YAHOO.widget.DataTable.Formatter.myCustom = myCustomFormatter;

            // Override the built-in formatter
            YAHOO.widget.DataTable.formatEmail = function(elCell, oRecord, oColumn, oData) {
                var user = oData;
                elCell.innerHTML = "<a href=\"mailto:" + user + "@mycompany.com\">" + user + "</a>";
            };
			
            var myColumnDefs = [
                {key:"check", formatter:YAHOO.widget.DataTable.formatCheckbox}, // use the built-in checkbox formatter (shortcut)
                //{key:"button", label:"Show record data", formatter:YAHOO.widget.DataTable.formatButton}, // use the built-in button formatter
                {key:"representation", formatter:YAHOO.widget.DataTable.formatDropdown, dropdownOptions:["mark","track","line","chart"],sortable:true},
				{key:"view", formatter:YAHOO.widget.DataTable.formatDropdown, dropdownOptions:["zoom","band","chromosome","karyotype"],sortable:true},
                {key:"uri", sortable:true},
                {key:"title", sortable:true}
            ];
			
			if(requestName=="cipf"){
				myColumnDefs.push({key:"description"});
			}
			
			//console.log(dasRegistryResults.sources);
			var myDataSource = new YAHOO.util.DataSource(dasSources);
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
            myDataSource.responseSchema = 

			{
                fields: [
					{key:"uri"},
                    {key:"title"},
                    {key:"description"},
					{key:"url"}
					//{key:"capability"}
                ]
            };
 
			//console.log(myDataSource);
            //var mySourceDataTable = new YAHOO.widget.DataTable("formatting", myColumnDefs, myDataSource);
			YAHOO.dasRegistry.mySourceDataTable = new YAHOO.widget.DataTable("KDsources", myColumnDefs, myDataSource);
			
			var mySourceDataTable = YAHOO.dasRegistry.mySourceDataTable;

            mySourceDataTable.subscribe("checkboxClickEvent", function(oArgs){
                var elCheckbox = oArgs.target;
                var oRecord = this.getRecord(elCheckbox);
                oRecord.setData("check",elCheckbox.checked);
            });

            mySourceDataTable.subscribe("buttonClickEvent", function(oArgs){
                var oRecord = this.getRecord(oArgs.target);
				//console.log(oArgs);
                alert(YAHOO.lang.dump(oRecord.getData()));
				//console.log(oRecord.getData());
				
            });
			
            mySourceDataTable.subscribe("dropdownChangeEvent", function(oArgs){
                var elDropdown = oArgs.target;
                var oRecord = this.getRecord(elDropdown);
				var selectedValue = elDropdown.options[elDropdown.selectedIndex].value;
				var dataKey = "view";
				if(selectedValue == "chart" || selectedValue == "line" || selectedValue == "track" || selectedValue == "mark"){
					dataKey = "representation";
				}
                oRecord.setData(dataKey,selectedValue);
            });
            return {
                oDS: myDataSource,
                oDT: mySourceDataTable
            };
}



YAHOO.dasRegistry.setButton = function(divContainer, buttonContent){
	var KDSContainer = document.getElementById(divContainer);
	KDSContainer.innerHTML = "";
	var eKDSContainer = new YAHOO.util.Element(KDSContainer);
	
	var buttonCont = document.createElement("button");
	var eButtonCont = new YAHOO.util.Element(buttonCont);
	eButtonCont.set('id', "viewButton");
	eButtonCont.appendChild(document.createTextNode(buttonContent));
	eKDSContainer.appendChild(eButtonCont);
}


 function selectAll() {
   var mySourceDataTable = YAHOO.dasRegistry.mySourceDataTable;
   records = mySourceDataTable.getRecordSet().getRecords();
   for (i=0; i < records.length; i++) {
        mySourceDataTable.getRecordSet().updateKey(records[i], "check", "true");
    }
   mySourceDataTable.refreshView();
   return false;
}

 function unselectAll() {
   var mySourceDataTable = YAHOO.dasRegistry.mySourceDataTable;
   records = mySourceDataTable.getRecordSet().getRecords();
   for (i=0; i < records.length; i++) {
        mySourceDataTable.getRecordSet().updateKey(records[i], "check", "");
    }
   mySourceDataTable.refreshView();
   return false;
}

function getListOfSources() {
	sessvars.karyoDas.conf.sources = new Array();
	var mySourceDataTable = YAHOO.dasRegistry.mySourceDataTable;
	records = mySourceDataTable.getRecordSet().getRecords();
	for (i=0; i < records.length; i++) {
		var isChecked = false;
		if(records[i].getData("check")==true){
			isChecked = true;
		}
		if(isChecked){
			var source = new Object();
			source.id = records[i].getData("uri");
			source.url = records[i].getData("url");
			source.name = records[i].getData("title");
			source.label =['KARYODAS'];
			source.description = records[i].getData("description");
			
			if(records[i].getData("representation")!=undefined){
				source.representation = records[i].getData("representation");
			} else {
				source.representation = 'mark';
			}	
			
			if(records[i].getData("view")!=undefined){
				source.panel = records[i].getData("view");
			} else {
				source.panel = 'zoom';
			}

			source.ntLimit =null;
			source.types = [];
			source.stylesheet = true;
			sessvars.karyoDas.conf.sources.push(source);
		}
		
		//console.log(records[i].getData("uri"));	
		//mySourceDataTable.getRecordSet().updateKey(records[i], "check", "true");
	}
	//mySourceDataTable.refreshView();
	//console.log(sessvars.karyoDas.conf.sources);
	return true;
}

function viewButtonCallback(e) {
	getListOfSources();
	window.location="display.html";
}
